package com.xgpro.pc.rolemanage.controller;


import com.xgpro.common.results.ResponseResult;
import com.xgpro.domain.rolemanage.entity.Role;
import com.xgpro.pc.rolemanage.service.RoleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: xg_hrm
 * @Description: 角色管理接口
 * @Author: LiKai
 * @Date: 2019-09-07 11:21
 **/
@CrossOrigin(allowCredentials="true")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/addRole",method = RequestMethod.POST)
    public ResponseResult addRole(@RequestBody Role role) {
        return roleService.addRole(role);
    }

    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/deleteRole",method = RequestMethod.DELETE)
    public ResponseResult deleteRole(@RequestParam("ids") List<Integer> ids) {
        return roleService.deleteRole(ids);
    }

    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/updateRole",method = RequestMethod.PUT)
    public ResponseResult updateRole(@RequestBody Role role) {
        return roleService.updateRole(role);
    }

    /**
     * 获取角色列表
     * @param page
     * @param size
     * @param map
     * @return
     */

    @RequestMapping(value = "/getRole",method = RequestMethod.GET)
    public ResponseResult getRole(@RequestParam int page, @RequestParam int size, @RequestParam(required = false) Map map) {
        return roleService.getRole(page,size,map);
    }

    /**
     * 权限角色详情
     * @param roleId
     * @return
     */
    @GetMapping(value = "/getRole/{roleId}")
    public ResponseResult findOne(@PathVariable Integer roleId){

        Role role = roleService.findOne(roleId);

        return ResponseResult.ok(role);

    }

}
